"""
@author: Sergiy Tsymbalyuk
"""

from sqlalchemy import Column, ForeignKey, UniqueConstraint
from sqlalchemy.types import Integer, Numeric

from pylons.i18n import lazy_ugettext as _

from pubservices.model.meta import Base
from chowa.model import District

__all__ = ['Communications']


money = lambda verbose: Column(Numeric(10, 2), info={'verbose':verbose, 'total':'sum'})

class Communications(Base):
    __tablename__ = 'pubservices_communications'
    __table_args__ = (UniqueConstraint('year', 'month', 'decade', 'district_id'),)
    
    id = Column(Integer, primary_key=True, info={'no-change': True})
    
    year = Column(Integer, info={'no-change': True, 'verbose': _('year')})
    month = Column(Integer, info={'no-change': True, 'verbose': _('month')})
    decade = Column(Integer, info={'no-change': True, 'verbose': _('decade')})
    district_id = Column(Integer, ForeignKey(District.id),
                         info={'no-change': True, 'verbose': _('district')})
    
    budget = Column(Numeric(10, 2), info={'verbose': _('budget'), 'total': 'max'})
    phones = Column(Integer, info={'verbose': _('number of phones'), 'total': 'max'})
    subscription = money(_('subscription fee'))
    local_amount = money(_('charge for local calls'))
    phone_install = money(_('phone installation'))
    
    ldts_calls = Column(Integer, info={'verbose': _('Number of calls'), 'total': 'sum'})
    ldts_seconds = Column(Integer, info={'verbose': _('Time of calls (seconds)'), 'total': 'sum'})
    ldts_amount = money(_('Charge for calls'))
    
    channel = money(_('Dediacated channel'))
    adsl = money(_('ADSL'))
    fax = money(_('Fax'))
    login = money(_('Login'))
    security = money(_('Protection'))
    radio = money(_('Radio'))
    other = money(_('Other'))
